package site.sorghum.ddl.solon.config;

import org.noear.solon.annotation.Bean;
import org.noear.solon.annotation.Condition;
import org.noear.solon.annotation.Configuration;
import org.noear.solon.annotation.Inject;
import org.noear.wood.DbContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import site.sorghum.ddl.solon.prop.GlobalConfigProp;
import site.sorghum.ddl.wood.WoodDdlWrapper;
import site.sorghum.ddl.wood.WoodEntityGenerate;
import site.sorghum.ddl.wood.WoodInitConfig;

@Configuration
@org.springframework.context.annotation.Configuration
@Condition(onClass = WoodInitConfig.class)
@ConditionalOnClass(value = WoodInitConfig.class)
public class WoodConfig {

    @Bean
    @org.springframework.context.annotation.Bean
    public WoodEntityGenerate woodEntityGenerate() {
        return new WoodEntityGenerate();
    }


    @Bean
    @org.springframework.context.annotation.Bean
    public WoodDdlWrapper woodDdlWrapper(@Autowired @Inject DbContext dbContext) {
        return new WoodDdlWrapper(dbContext);
    }


    @Bean
    @org.springframework.context.annotation.Bean
    public WoodInitConfig woodInitConfig(@Autowired(required = false) @Inject(required = false) GlobalConfigProp globalConfig,
                                         @Autowired @Inject WoodDdlWrapper woodDdlWrapper,
                                         @Autowired @Inject WoodEntityGenerate woodEntityGenerate) {
        if (globalConfig != null) {
            globalConfig.init();
        }
        return new WoodInitConfig(woodDdlWrapper, woodEntityGenerate);
    }
}
